﻿using System.Web.UI;
using System.Web.UI.WebControls;
using Ue.Framework.Web.WebControls;
using Ue.Infrastructure.Web.UI;

namespace Ue.Qcdz.UI.Controls.Adver
{
    public class AdvertisementEdit : SkinnedEntityEdit<Ue.Qcdz.Domain.Adver.Advertisement>
    {
        private TextBox tbxWebSiteName;
        private TextBox tbxDivId;
        private TextBox tbxAdType;
        private TextBox tbxAdSize;
        private TextBox tbxAdUrl;
        private TextBox tbxAdLink;
        private TextBox tbxPageName;
        private TextBox tbxRemark;
        
        private string skinFileName = "~/Admin/Themes/Skins/Adver/AdvertisementEdit.ascx";
        #region Overrides of SkinnedControl

        protected override string GetSkinFileName()
        {
            return skinFileName;
        }

        #endregion

        #region Overrides of SkinnedEntityEdit<Advertisement>

        protected override Domain.Adver.Advertisement Enttiy
        {
            get
            {
                if(this.Action=="Delete")
                {
                    return new Domain.Adver.Advertisement(this.EntityKey);
                }
               
                string strWebSiteName = tbxWebSiteName.GetValue<string>();
                string strDivId = tbxDivId.GetValue<string>();
                string strAdType = tbxAdType.GetValue<string>();
                string strAdSize = tbxAdSize.GetValue<string>();
                string strAdUrl = tbxAdUrl.GetValue<string>();
                string strAdLink = tbxAdLink.GetValue<string>();
                string strPageName = tbxPageName.GetValue<string>();
                string strRemark = tbxRemark.GetValue<string>();
                var advertisement = new Domain.Adver.Advertisement(strWebSiteName, strDivId, strAdType, strAdSize, strAdUrl, strAdLink, strPageName, strRemark,this.EntityKey);
                return advertisement;
            }
            set
            {
                if(value==null)
                    return;
                tbxWebSiteName.SetValue(value.WebSiteName);
                tbxDivId.SetValue(value.DivId);
                tbxAdType.SetValue(value.AdType);
                tbxAdSize.SetValue(value.AdSize);
                tbxAdUrl.SetValue(value.AdUrl);
                tbxAdLink.SetValue(value.AdLink);
                tbxPageName.SetValue(value.PageName);
                tbxWebSiteName.Enabled = false;
                tbxPageName.Enabled = false;
                tbxDivId.Enabled = false;
            }
        }

        protected override void InitSkin(Control skin)
        {
            tbxWebSiteName =  skin.FindControl<TextBox>("tbxWebSiteName");
            tbxWebSiteName.SetValue("qcdz");
            tbxDivId = skin.FindControl<TextBox>("tbxDivId");
            tbxAdType = skin.FindControl<TextBox>("tbxAdType");
            tbxAdSize = skin.FindControl<TextBox>("tbxAdSize");
            tbxAdUrl = skin.FindControl<TextBox>("tbxAdUrl");
            tbxRemark = skin.FindControl<TextBox>("tbxRemark");
            tbxAdLink = skin.FindControl<TextBox>("tbxAdLink");
            tbxPageName = skin.FindControl<TextBox>("tbxPageName");
            if(tbxAdLink!=null)
            {
                tbxAdLink.Text = "http://";
            }
        }

        #endregion
    }
}
